using System;
using System.Collections.Generic;
using System.Text;
using Xunit;
using Common.Shared.Net;
using Common.Shared.Json.Serialization;
using System.IO;

namespace Common.Shared.Tests {
	public class JsonSerializerTests {

		[Fact]
		public void SerializeTest() {
			try {
				ProxyInfo pi = new ProxyInfo ( );
				pi.ProxyPort = 8080;
				pi.ProxyServer = "proxy.ups.com";
				pi.Name = "ups";
				pi.Username = "trr4rac";
				pi.Password = "p@ssw0rd1";
				pi.BypassLocal = true;
				pi.BypassList.Add ( "ups.com" );
				pi.BypassList.Add ( "upsers.com" );
				pi.BypassList.Add ( "10.*" );
				pi.RequiresLogin = true;
				pi.OverrideDefaultProxy = false;
				pi.Enabled = true;

				JsonSerializer<ProxyInfo> serialzier = new JsonSerializer<ProxyInfo> ( );
				using ( FileStream fs = new FileStream ( "c:\\proxy.json", FileMode.Create, FileAccess.Write ) ) {
					serialzier.Serialize ( fs, pi,true );
				}

				using ( FileStream fs = new FileStream ( "c:\\proxy-formatted.json", FileMode.Create, FileAccess.Write ) ) {
					serialzier.Serialize ( fs, pi,false );
				}
			} catch ( Exception ex ) {
				Console.WriteLine ( ex.ToString ( ) );
			}
		}
	}
}
